package com.example.dynamicdatasourcedemo.controller;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.dynamicdatasourcedemo.entity.User;
import com.example.dynamicdatasourcedemo.service.UserService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.beans.Transient;

/**
 *   
 *  Created with IDEA  
 *  @author:尚旭波  
 *  @Date:2018/8/2  
 *  @Time:10:54    
 *  
 */
@Slf4j
@Controller
@RequestMapping("/test")
public class UserController {


    @Autowired
    private UserService userService;


    @ResponseBody
    @RequestMapping("/testDynamicDataSourcedemo")
    public void testDynamicDataSourcedemo(User user) {
        log.info("requestParamer:{}", user);
        userService.addUser(user);
    }


    @ResponseBody
    @RequestMapping("/testtestDynamicDataSourcedemoBySlave")
    public void testtestDynamicDataSourcedemoBySlave(User user) {
        log.info("requestParamer:{}", user);
        userService.addUser(user);
    }


    @ResponseBody
    @RequestMapping("/testTransactional")
    @Transactional(rollbackFor = Exception.class)
    public void testTransactional(User user) {
        log.info("requestParamer:{}", user);
        userService.addUserBySlave(user);

        userService.addUserByMaster(user);

        log.debug("success");


    }

}
